package com.sejong.andproject;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.Vector;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import com.sejong.andproject.R;

import net.daum.mf.map.api.MapPoint;
import net.daum.mf.map.api.MapView;
import net.daum.mf.map.api.MapView.MapViewEventListener;
import android.app.Activity;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class mapinfo extends Activity implements MapViewEventListener {

	private MapView mapView;
	private String latitude;
	private String longitude;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	
	    // TODO Auto-generated method stub
	    
	    setContentView(R.layout.childinfo);
	    
	    httpsend htpsend = new httpsend();
	    htpsend.start();
	    
	    mapView = (MapView)findViewById(R.id.daumMapView);
	    mapView.setDaumMapApiKey("711e41c3c0bd98bcac407fb8e447fbce80434f84");
	    mapView.setMapViewEventListener(this);
	    
	}

	public void onMapViewCenterPointMoved(MapView arg0, MapPoint arg1) {
		// TODO Auto-generated method stub
		
		mapView.setMapCenterPointAndZoomLevel(MapPoint.mapPointWithCONGCoord(33.41,126.52),9, true);
		
	}

	public void onMapViewDoubleTapped(MapView arg0, MapPoint arg1) {
		// TODO Auto-generated method stub
		
	}

	public void onMapViewInitialized(MapView arg0) {
		// TODO Auto-generated method stub
		
	}

	public void onMapViewLongPressed(MapView arg0, MapPoint arg1) {
		// TODO Auto-generated method stub
		
	}

	public void onMapViewSingleTapped(MapView arg0, MapPoint arg1) {
		// TODO Auto-generated method stub
		
	}

	public void onMapViewZoomLevelChanged(MapView arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}
	

private String sendToServer() throws ClientProtocolException, IOException{
	
	HttpPost request = makeHttpPost("ok","http://comms2012.dothome.co.kr/project/getUserLocaion.php");
	
	HttpClient client = new DefaultHttpClient();
	ResponseHandler<String> reshandler = new BasicResponseHandler();
	String result = client.execute(request,reshandler);
	return result;
	
}
private HttpPost makeHttpPost(String $longitude,  String $url){
	HttpPost request = new HttpPost($url);
	Vector<NameValuePair> nameValue = new Vector<NameValuePair>();
	nameValue.add(new BasicNameValuePair("info", $longitude));
	request.setEntity(makeEntity(nameValue));
	
	
	
	return request;
	
	
}
private HttpEntity makeEntity(Vector<NameValuePair> $namevalue){
	HttpEntity result = null;
	
	try{
		
		result = new UrlEncodedFormEntity($namevalue);
		
	}catch(UnsupportedEncodingException e){
		e.printStackTrace();
		
	}
	
	return result;
	
	
}
public class httpsend extends Thread{
	//TextView textview02 = (TextView)findViewById(R.id.textview02);
	String loginfo;
	public void run(){
		   try {
				loginfo = sendToServer();
				Log.i("RESPONSE : ", loginfo);
			} catch (ClientProtocolException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	
		
	}
  }


}
